package cn.hesion.thread.productandconsumer;
/**
 * ClassName: Foodie <br/>
 * Description: <br/>
 * date: 2022/6/6 14:02<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

/**
 * 吃货
 * @author: hesion
 * @create: 2022-06-06 14:02
 **/
public class Foodie extends Thread{

    @Override
    public void run() {
        while (true){
            synchronized (Desk.lock){
                if(Desk.count == 0){
                    break;
                }else {
                    if(Desk.flag){
                        //有
                        System.out.println(Thread.currentThread().getName()+" 吃货在吃汉堡包");
                        Desk.flag = false;
                        Desk.lock.notifyAll();
                        --Desk.count;
                    }else {
                        //没有则等待
                        //
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }

        }
    }
}
